package com.czy.controller;

import com.czy.utils.QRCodeUtils;
import com.google.zxing.Result;
import com.google.zxing.WriterException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

/**
 * @Author chenzy
 * @Date 2020/9/30 9:11
 * @Version 1.0
 * @Description
 */
@Controller
@RequestMapping(value = "/test")
public class QRCodeUtilsController {

    @ResponseBody
    @RequestMapping(value = "testDemo", method = RequestMethod.POST)
    public Result testDemo(HttpServletResponse response){
        try {
            ByteArrayOutputStream stream = QRCodeUtils.create("https://www.baidu.com/",300,300);
            byte[] bytes = stream.toByteArray();
            ServletOutputStream outputStream = response.getOutputStream();
            outputStream.write(bytes);
        } catch (WriterException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }



}
